﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufText.h"
#include "GnufQtItem.h"
#include <QtWidgets/QWidget>
#include <QLineEdit>
#include "GnufAppearanceSetting.h"
class QLabel;
class QLineEdit;
class QValidator;

namespace gnuf {
    class Text;
    class QtTextImpl;

    class QtText final : public QtItemWith<QLineEdit, Text, QWidget*>
    {
        Q_OBJECT
    public:
        QtText(Text * text, QWidget * qtParentWidget = nullptr);
        virtual ~QtText();

        static bool turnOnJournalUiRecorder();
        static bool turnOffJournalUiRecorder();

        void assignText(const std::wstring &);
        std::wstring getText() const;

        void setValidator(const std::wstring& validator);

        virtual void refresh(EWhatDirty) override;
        void onTableRowSelectionChanged(bool);
    protected:
        virtual bool event(QEvent* qtEvt) override;
        virtual void mousePressEvent(QMouseEvent*) override;
        virtual void focusInEvent(QFocusEvent* e) override;
        virtual void focusOutEvent(QFocusEvent* e) override;
        virtual void hideEvent(QHideEvent* event) override;
        virtual QSize sizeHint() const override;
    private:
        void onEditingFinished();
        void adjustStyle(bool bSelected);
        void onTextChanged(const QString &);

        bool m_error;
        bool m_isElided;

        gcmp::OwnerPtr< QtTextImpl > m_opImpl;
    };
}
